import React, { Component } from 'react';
import { withRouter } from 'react-router-dom'
import './Seckill.scss'
import service from '../../api';


interface State {
    seckillList: []
}

class Index extends Component<any, State> {
    constructor(props: any) {
        super(props);
        this.state = {
            seckillList: []
        }
    }
    async componentDidMount() {
        // 秒杀数据请求
        var res = await service.pro.seckillList()
        // console.log(res.data.data);
        this.setState({
            seckillList: res.data.data
        })
    }

    // 去详情页
    toDetail(id:any){
        // console.log(id);       
        this.props.history.push({pathname:'/detail', state:{id}})
    }

    render() {
        return (
            <div className='seckill'>
                <div className="top">
                    <div className="left">
                        <span>嗨购秒杀</span>
                        <p>22点场</p>
                    </div>
                    <p>爆款轮番秒</p>
                </div>
                <div className="bottom">
                    {
                        this.state.seckillList.map((item:any, index) => {
                            return (
                                <div className="box" key={index} onClick={()=>{this.toDetail(item.proid)}}>
                                    <img src={item.img1} alt="" />
                                    <div className="name">¥{item.originprice}</div>
                                </div>
                            )
                        })

                    }
                </div>
            </div>
        );
    }
}

export default withRouter(Index);